#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int N = 510;
vector<int> as[N];
int id[N];
bool st[N];
int n;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x, y, z;
        cin >> x >> y;
        st[x] = true;
        while (y--)
        {
            cin >> z;
            as[x].push_back(z);
            id[z]++;
        }

    }
    queue<int> q;
    for (int i = 1; i <= n; i++)
    {
        if (st[i] && id[i] == 0)
        {
            q.push(i);
        }
    }
    while (q.size())
    {
        int a = q.front();
        q.pop();
        for (auto e : as[a])
        {
            id[e]--;
            if (st[e] && id[e] == 0)
            {
                q.push(e);
            }
        }
    }
    int ret = 0;
    for (int i = 1; i <= 500; i++)
    {
        if (st[i] && id[i])
        {
            ret++;
        }
    }
    if (ret == 0)
    {
        cout << "YES";
    }
    else
    {
        cout << ret;
    }

    return 0;
}